package com.taobao.publisher;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class MqSendService {

    // RabbitTemplate 是 Spring AMQP 提供的一个用于与 RabbitMQ 交互的模板类
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void testSendDirect() {
        String exchangeName = "taobao.direct";
        String msg = "蓝色通知，警报解除，哥斯拉是放的气球";
        rabbitTemplate.convertAndSend(exchangeName, "work1", msg);
    }

    public void testSendObject() {
        Map<String, Object> msg = new HashMap<>(2);
        msg.put("name", "jack");
        msg.put("age", 21);
        rabbitTemplate.convertAndSend("object.queue", msg);
    }


}
